trying a custom buildpack to customize Procfile

Andrew Cantino 10 ans auparavant
Parent
Commettre
1f3553dddd
6 fichiers modifiés avec 32 ajouts et 41 suppressions
  1. 2 0
      .buildpacks
  2. 8 5
      Gemfile
  3. 0 15
      Gemfile.lock
  4. 2 4
      Procfile
  5. 19 17
      bin/setup_heroku
  6. 1 0
      deployment/heroku/Procfile.heroku

+ 2 - 0
.buildpacks

@@ -0,0 +1,2 @@
1
+https://github.com/cantino/heroku-selectable-procfile.git
2
+https://github.com/heroku/heroku-buildpack-ruby.git

+ 8 - 5
Gemfile

@@ -22,6 +22,7 @@ else
22 22
   gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]
23 23
 end
24 24
 
25
+gem 'mysql2', '~> 0.3.16'
25 26
 gem 'devise', '~> 3.2.4'
26 27
 gem 'kaminari', '~> 0.16.1'
27 28
 gem 'bootstrap-kaminari-views', '~> 0.0.3'
@@ -75,11 +76,6 @@ gem 'slack-notifier', '~> 0.5.0'
75 76
 gem 'therubyracer', '~> 0.12.1'
76 77
 gem 'mqtt'
77 78
 
78
-gem 'mysql2', '~> 0.3.16', groups: [:development, :test]
79
-gem 'pg', group: :production
80
-gem 'unicorn', groups: [:development, :production]
81
-gem 'rails_12factor', group: :production
82
-
83 79
 group :development do
84 80
   gem 'binding_of_caller'
85 81
   gem 'better_errors'
@@ -103,3 +99,10 @@ group :production do
103 99
   gem 'dotenv-deployment'
104 100
   gem 'rack'
105 101
 end
102
+
103
+if ENV['ON_HEROKU'] || ENV['HEROKU_POSTGRESQL_ROSE_URL']
104
+  gem 'pg', group: :production
105
+  gem 'unicorn', groups: [:development, :production]
106
+  gem 'rails_12factor', group: :production
107
+end
108
+

+ 0 - 15
Gemfile.lock

@@ -161,7 +161,6 @@ GEM
161 161
     kaminari (0.16.1)
162 162
       actionpack (>= 3.0.0)
163 163
       activesupport (>= 3.0.0)
164
-    kgio (2.8.0)
165 164
     kramdown (1.3.3)
166 165
     launchy (2.4.2)
167 166
       addressable (~> 2.3)
@@ -193,7 +192,6 @@ GEM
193 192
       multi_xml (~> 0.5)
194 193
       rack (~> 1.2)
195 194
     orm_adapter (0.5.0)
196
-    pg (0.17.1)
197 195
     polyglot (0.3.5)
198 196
     protected_attributes (1.0.8)
199 197
       activemodel (>= 4.0.1, < 5.0)
@@ -216,17 +214,11 @@ GEM
216 214
       bundler (>= 1.3.0, < 2.0)
217 215
       railties (= 4.1.4)
218 216
       sprockets-rails (~> 2.0)
219
-    rails_12factor (0.0.2)
220
-      rails_serve_static_assets
221
-      rails_stdout_logging
222
-    rails_serve_static_assets (0.0.2)
223
-    rails_stdout_logging (0.0.3)
224 217
     railties (4.1.4)
225 218
       actionpack (= 4.1.4)
226 219
       activesupport (= 4.1.4)
227 220
       rake (>= 0.8.7)
228 221
       thor (>= 0.18.1, < 2.0)
229
-    raindrops (0.11.0)
230 222
     rake (10.3.2)
231 223
     ref (1.0.5)
232 224
     rest-client (1.6.7)
@@ -325,10 +317,6 @@ GEM
325 317
     uglifier (2.5.1)
326 318
       execjs (>= 0.3.0)
327 319
       json (>= 1.8.0)
328
-    unicorn (4.6.3)
329
-      kgio (~> 2.6)
330
-      rack
331
-      raindrops (~> 0.7)
332 320
     uuid (2.3.7)
333 321
       macaddr (~> 1.0)
334 322
     uuidtools (2.1.4)
@@ -386,13 +374,11 @@ DEPENDENCIES
386 374
   mqtt
387 375
   mysql2 (~> 0.3.16)
388 376
   nokogiri (~> 1.6.1)
389
-  pg
390 377
   protected_attributes (~> 1.0.8)
391 378
   pry
392 379
   quiet_assets
393 380
   rack
394 381
   rails (= 4.1.4)
395
-  rails_12factor
396 382
   rr
397 383
   rspec (~> 2.14)
398 384
   rspec-rails (~> 2.14)
@@ -409,7 +395,6 @@ DEPENDENCIES
409 395
   typhoeus (~> 0.6.3)
410 396
   tzinfo-data
411 397
   uglifier (>= 1.3.0)
412
-  unicorn
413 398
   vcr
414 399
   webmock (~> 1.17.4)
415 400
   weibo_2 (~> 0.1.4)

+ 2 - 4
Procfile

@@ -1,8 +1,6 @@
1 1
 # Procfile for development using the new threaded worker (scheduler, twitter stream and delayed job)
2
-# web: bundle exec rails server
3
-# jobs: bundle exec rails runner bin/threaded.rb
4
-
5
-web: bundle exec unicorn -p $PORT -c ./deployment/heroku/unicorn.rb
2
+web: bundle exec rails server
3
+jobs: bundle exec rails runner bin/threaded.rb
6 4
 
7 5
 # Possible Profile configuration for production:
8 6
 # web: bundle exec unicorn -c config/unicorn/production.rb

+ 19 - 17
bin/setup_heroku

@@ -45,6 +45,13 @@ def grab_heroku_config
45 45
   config
46 46
 end
47 47
 
48
+def set_value(key, value, options = {})
49
+  unless config[key] == value
50
+    puts "Setting #{key} to #{value}" unless options[:silent]
51
+    puts capture("heroku config:set #{key}=#{value}")
52
+  end
53
+end
54
+
48 55
 unless File.exists?(File.expand_path("~/.netrc")) && File.read(File.expand_path("~/.netrc")) =~ /heroku/
49 56
   puts "It looks like you need to log in to Heroku.  Please run 'heroku auth:login' before continuing."
50 57
   exit 1
@@ -87,15 +94,11 @@ unless config['APP_SECRET_TOKEN']
87 94
   puts capture("heroku config:set APP_SECRET_TOKEN=`rake secret`")
88 95
 end
89 96
 
90
-unless config['FORCE_SSL']
91
-  puts "Setting FORCE_SSL to true..."
92
-  puts capture("heroku config:set FORCE_SSL=true")
93
-end
94
-
95
-unless config['DOMAIN']
96
-  puts "Setting DOMAIN to #{app_name}.herokuapp.com..."
97
-  puts capture("heroku config:set DOMAIN=#{app_name}.herokuapp.com")
98
-end
97
+set_value 'BUILDPACK_URL', "https://github.com/ddollar/heroku-buildpack-multi.git"
98
+set_value 'PROCFILE_PATH', "deployment/heroku/Procfile.heroku"
99
+set_value 'ON_HEROKU', "true"
100
+set_value 'FORCE_SSL', "true"
101
+set_value 'DOMAIN', "#{app_name}.herokuapp.com"
99 102
 
100 103
 unless config['INVITATION_CODE']
101 104
   puts "You need to set an invitation code for your Huginn instance.  If you plan to share this instance, you will"
@@ -103,8 +106,7 @@ unless config['INVITATION_CODE']
103 106
   puts "that people will not guess."
104 107
 
105 108
   invitation_code = nag("What code would you like to use?")
106
-  puts "Setting INVITATION_CODE to #{invitation_code}..."
107
-  puts capture("heroku config:set INVITATION_CODE=#{invitation_code}")
109
+  set_value 'INVITATION_CODE', invitation_code
108 110
 end
109 111
 
110 112
 unless config['SMTP_DOMAIN'] && config['SMTP_USER_NAME'] && config['SMTP_PASSWORD'] && config['SMTP_SERVER'] && config['EMAIL_FROM_ADDRESS']
@@ -113,20 +115,20 @@ unless config['SMTP_DOMAIN'] && config['SMTP_USER_NAME'] && config['SMTP_PASSWOR
113 115
   puts "SMTP_DOMAIN, SMTP_USER_NAME, SMTP_PASSWORD, and SMTP_SERVER with 'heroku config:set'."
114 116
   if yes?("Should I enable the free sendgrid addon?")
115 117
     puts capture("heroku addons:add sendgrid")
116
-    puts capture("heroku config:set SMTP_SERVER=smtp.sendgrid.net")
117
-    puts capture("heroku config:set SMTP_DOMAIN=heroku.com")
118
+
119
+    set_value 'SMTP_SERVER', "smtp.sendgrid.net", silent: true
120
+    set_value 'SMTP_DOMAIN', "heroku.com", silent: true
118 121
 
119 122
     config = grab_heroku_config
120
-    puts capture("heroku config:set SMTP_USER_NAME=#{config['SENDGRID_USERNAME']}")
121
-    puts capture("heroku config:set SMTP_PASSWORD=#{config['SENDGRID_PASSWORD']}")
123
+    set_value 'SMTP_USER_NAME', config['SENDGRID_USERNAME'], silent: true
124
+    set_value 'SMTP_PASSWORD', config['SENDGRID_PASSWORD'], silent: true
122 125
   else
123 126
     puts "Okay, you'll need to set SMTP_DOMAIN, SMTP_USER_NAME, SMTP_PASSWORD, and SMTP_SERVER with 'heroku config:set' manually."
124 127
   end
125 128
 
126 129
   unless config['EMAIL_FROM_ADDRESS']
127 130
     email = nag("What email address would you like email to appear to be sent from?")
128
-    puts "Setting EMAIL_FROM_ADDRESS to #{email}..."
129
-    puts capture("heroku config:set EMAIL_FROM_ADDRESS=#{email}")
131
+    set_value 'EMAIL_FROM_ADDRESS', email
130 132
   end
131 133
 end
132 134
 

+ 1 - 0
deployment/heroku/Procfile.heroku

@@ -0,0 +1 @@
1
+web: bundle exec unicorn -p $PORT -c ./deployment/heroku/unicorn.rb